#############################
# PLOT DEPORTATION TIMELINE #
#############################

# Author: Kasia Nalewajko
# First version: 29 November 2022
# Replicated: 13 June 2024


rm(list=ls())

# LOAD PACKAGES -----------------------------------------------------------

if (!require("dplyr")) install.packages("dplyr")
if (!require("ggplot2")) install.packages("ggplot2")

# LOAD DATA -----

load("./00 SUBMITTED/00 APSR final/04 replication_files/01 data/klarsfeld.Rda")

# CLEAN -------

sum <- klarsfeld_db %>% 
  group_by(deportation_date, native) %>% 
  summarise(n = n())

sum$month <- as.Date(cut(sum$deportation_date,
                         breaks = "month"))
sum$week <- as.Date(cut(sum$deportation_date,
                        breaks = "week",
                        start.on.monday = TRUE)) # "FALSE" changes weekly break point to Sunday

sum$native <- factor(sum$native, levels=c("0", "1"), labels=c("no", "yes"))

# PLOT ----

sum %>%   
  ggplot(aes(x = month, y = n, fill = as.factor(native))) +
  stat_summary(fun = "sum", # adds up all observations for the month
               geom = "bar") + # or "line"
  scale_x_date(
    labels = scales::date_format("%Y-%m"),
    breaks = "1 month",
    limits = c(as.Date("1942-01", format = "%Y-%m"), as.Date("1944-09", format = "%Y-%m"))
  ) +
  labs(title = "",
       x = "Date",
       y = "Number deportees") +
  scale_fill_viridis_d("Born in France?", 
                       na.value = "grey",
                       option = "inferno",
                       begin = 0.2, end = 0.85) +
  theme_bw() +
  theme(axis.text.x=element_text(angle = 45, hjust = 1, vjust = 1, size = 7))

# SAVE ----

ggsave(filename = "C1_deportation_timeline_pob.png",
       plot = last_plot(),
       path = "./00 SUBMITTED/00 APSR final/03 dataverse_online_appendix/figures",
       width = 20,
       height = 10,
       units = "cm",
       dpi = 300)

